﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
using ClientCommonWpf;

namespace Director
{
	class TimeSeries<T>:AbstractNotifier
	{
		public bool IsContinuous { get; private set; }
		
		public T Last { get; private set; }

		public Dictionary<DateTime, T> Series { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="isContinuous">непрерывная линия или набор меток</param>
		public TimeSeries(bool isContinuous)
		{
			IsContinuous = isContinuous;
			Series = new Dictionary<DateTime, T>();
		}

		public void Add(DateTime dateTime, T value)
		{
			Series[dateTime] = value;
			Last = value;
			OnPropertyChanged(()=>Last);
		}

		public T this[DateTime dateTime]
		{
			get
			{
				T value;
				Series.TryGetValue(dateTime, out value);
				return value;
			}
		}
	}

	[ValueConversion(typeof (decimal), typeof (string))]
	public class StringFormatConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			if (value == null) return null;
			var v = (decimal)value;

			if (v == 0) return null;

			return v.ToString("N", new CultureInfo("ru-RU"));
		}


		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}
